﻿Imports System.Activities
Imports System.Activities.Presentation.Metadata
Imports System.Drawing
Imports System.ComponentModel

Public Class GetHashtableValue
    Inherits CodeActivity
    Implements IRegisterMetadata

    Public Property HashArgument As InArgument(Of Hashtable)
    Public Property KeyName As InArgument(Of String)
    Public Property Values As OutArgument(Of Object)

    Public Sub New()
        Me.DisplayName = My.Resources.GetHashtableValueDisplayName
    End Sub

    Protected Overrides Sub Execute(context As System.Activities.CodeActivityContext)
        Dim ht = context.GetValue(Me.HashArgument)
        Dim key = context.GetValue(Me.KeyName)

        If Not ht.ContainsKey(key) Then Return

        context.SetValue(Me.Values, ht.Item(key))
    End Sub


    Public Sub Register() Implements System.Activities.Presentation.Metadata.IRegisterMetadata.Register
        Dim build As New AttributeTableBuilder
        'WMIGetHashtableValue Activity
        build.AddCustomAttributes(GetType(GetHashtableValue),
                                              New DesignerAttribute(GetType(GetHashtableValueDesigner)),
                                              New ToolboxBitmapAttribute(GetType(GetHashtableValue), "GetHashtableValue.png"))

        build.AddCustomAttributes(GetType(GetHashtableValue), "DisplayName",
                                      New CategoryAttribute(My.Resources.CategorySetting),
                                      New DisplayNameAttribute(My.Resources.DisplayNameDisplay))

        build.AddCustomAttributes(GetType(GetHashtableValue), "HashArgument",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New RequiredArgumentAttribute(),
                                      New DisplayNameAttribute(My.Resources.HashArgumentDisplay),
                                      New DescriptionAttribute(My.Resources.HashArgumentDescription))
        build.AddCustomAttributes(GetType(GetHashtableValue), "KeyName",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New RequiredArgumentAttribute(),
                                      New DisplayNameAttribute(My.Resources.KeyNameDisplay),
                                      New DescriptionAttribute(My.Resources.KeyNameDescription))
        build.AddCustomAttributes(GetType(GetHashtableValue), "Values",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New DisplayNameAttribute(My.Resources.ValuesDisplay),
                                      New DescriptionAttribute(My.Resources.ValuesDescription))

        MetadataStore.AddAttributeTable(build.CreateTable)
    End Sub

End Class
